|
|
|
|
|
|
|
usually still visible to some extent because of ambient light. Ambient light is light that reaches an object after being reflected off other objects. |
|
|
|
|
|
|
|
|
In a typical room, objects hidden under desks and chairs are visible because ambient light reflected off the floor, walls, and other surfaces in the room illuminate them. Even if you turn off the lights during the day, the room is lit by ambient sunlight reflected by the sky and entering through windows. |
|
|
|
|
|
|
|
|
A simple way to model ambient light is to add a constant term Ia to indicate the amount of ambient light in the scene. Then give each object in the scene a constant factor ka that indicates how much of the ambient light is reflected by the object. For color, use three ambient light termsIred, Ia,green, and Ia,blueand three coefficients for each objectka,red, ka,green, and ka,blue. |
|
|
|
|
|
|
|
|
Determining exactly how much ambient light truly reaches a given object is very difficult. For example, when a dark object lies close to another object, the first object blocks some of the ambient light that would otherwise strike the second. Assuming the ambient light intensity Ia is constant throughout the scene is a good first approximation and is much easier. |
|
|
|
|
|
|
|
|
When the ambient light term is added to the component because of diffuse reflection, the intensity of light a viewer sees from an object is given by the equation: |
|
|
|
 |
|
|
|
|
I = Ia * ka + Ii * kd * (L · N) |
|
|
|
|
|
|
|
|
The only change you need to make to the SurfaceColor subroutine is to add the new ambient term. Note that this term does not depend on the light sources, so it is added only once. |
|
|
|
 |
|
|
|
|
' Add the ambient term. R = R + ambient_light * AmbientKr
G = G + ambient_light * AmbientKg
B = B + ambient_light * AmbientKb |
|
|
|
|
|
|
|
|
Example program Light2 is similar to program Light1, except it uses ambient light. Because the ambient term tends to make objects brighter, this program's light sources are slightly darker than those in program Light1. |
|
|
|
|
|
|
|
|
If two polygons lie in parallel planes, the angles their normals make with the vectors to a light source that is far away are almost the same. In that case, the two polygons are shaded with the same color. If one polygon overlaps the other, you cannot distinguish the boundary between them. |
|
|
|
|
|
|
|
|
Figure 16.4 shows this problem. The darkest faces on the four middle cubes have the same color. These faces overlap, so the boundary between them vanishes, making the picture more confusing. |
|
|
|
|
|